<!-- 随笔 -->
<script setup>
import { useBreadsStore } from '@/stores'
const { setBreadCrumbs } = useBreadsStore()
import { render, WC } from '@/utils/markdown'
import moment from 'moment'
import { RouterLink } from 'vue-router'
import useEssayInfo from './composable/useEssayInfo'
import LikeOrBad from '@/components/LikeOrBad.vue'

setBreadCrumbs([{ title: 'essay', path: '/essay/newest' }])

const { cur, total, essay } = useEssayInfo()
</script>

<template>
  <div class="loading" v-if="!essay">
    <div class="centre-text">loading</div>
  </div>
  <div class="views-wrapper" v-else>
    <div class="header">
      <div class="title">{{ essay.title }}</div>
      <div class="subtitle">{{ essay.subtitle }}</div>
    </div>
    <div class="diary-container">
      <div class="info">
        <div>{{ cur }} / {{ total }}</div>
        <div>WC: {{ WC(essay.content) }}</div>
      </div>
      <div class="content">
        <div class="sign">{{ essay.prefix }}</div>
        <div class="diary" v-html="render(essay.content)"></div>
        <div class="sign-end">{{ essay.suffix }}</div>
      </div>
    </div>
    <div class="footer">
      <div class="ops">
        <div class="ops">
          <RouterLink class="op-wrapper" :to="`/essay/${cur > 1 ? cur - 1 : total}`">
            <span class="icon icon-prev"> </span>
          </RouterLink>
          <RouterLink class="op-wrapper" :to="`/essay/${cur < total ? cur + 1 : 1}`">
            <span class="icon icon-next"> </span>
          </RouterLink>
        </div>
        <!-- <LikeOrBad :init-cnt="1000" :init-status="false" :object-id="1" object-type="2"></LikeOrBad> -->
      </div>
      <div class="footer-right">
        <div>{{ essay.views }}</div>
        <div class="time">{{ moment(essay.createTime).format('HH:mm:ss YYYY-MM-DD') }}</div>
      </div>
    </div>
  </div>

</template>

<style scoped lang="scss">
.loading {
  flex: 1;
}

.views-wrapper {
  flex: 1;
  margin: 50px auto;
  width: 65%;
  background: var(--site-home-bgc);
  box-shadow: 0px 3px 4px var(--site-home-shadow);
  border: 1px solid var(--border-primary);
  min-height: 300px;
  display: flex;
  flex-direction: column;

  @media screen and (max-width: 768px) {
    width: 98%;
  }
}

.header {
  margin: 10px 0;
  padding: 0 0 10px;
  box-shadow: 0px 3px 4px var(--site-home-shadow);
  background: var(--linear-03);

  .title {
    padding-top: 10px;
    padding-bottom: 0px;
    font-family: "Oswald", "Bookman Old Style", serif;
    font-size: 2.50rem;
    border-bottom: 1px solid rgb(0, 63, 0);
    letter-spacing: 0.12rem;
    width: max-content;
    margin: auto;
    color: rgb(0, 103, 0);
  }

  .subtitle {
    font-family: Roboto, inherit "Merienda", sans-serif;
    font-weight: 400;
    font-size: .75rem;
    color: var(--site-home-subtitle);
    letter-spacing: 0.100rem;
    margin: auto;
    width: max-content;
  }
}

.diary-container {
  margin: 0 20px 20px;
  padding: 10px;
  flex: 1;
  display: flex;
  justify-content: space-around;
  align-items: center;
  flex-direction: column;

  .info {
    display: flex;
    justify-content: space-between;
    width: 100%;
    font-size: 0.8rem;
    color: var(--text-02);
  }

  .content {
    flex: 1;
    margin: 10px 0;
    display: flex;
    justify-content: space-around;
    width: 100%;
    display: grid;
    // grid-template-columns: 10% auto 10%;

    .sign {
      margin-left: auto;
      font-weight: bold;
    }

    .sign-end {
      margin-top: auto;
      font-weight: bold;
    }

    .diary {
      text-indent: 2em;
      // background-color: #fff;
      line-height: 1.5;
    }
  }

}

.footer {
  display: flex;
  justify-content: space-between;
  padding: 1em 1em;
  border-top: 1px dotted var(--text-02);

  @media screen and (max-width: 425px) {
    // flex-direction: column;
  }

  .ops {
    display: flex;
    justify-content: space-between;
    gap: 2em;
  }

  .op-wrapper {
    cursor: pointer;

    & .icon {
      transition: all .3s ease-out;
      mask-repeat: no-repeat;
      mask-position: center;
      vertical-align: middle;
      display: inline-block;
      background-color: var(--text-02);
      mask-image: url('/static/svg/bread.svg');
      width: 15px;
      height: 15px;
    }

    & .icon-prev {
      transform: rotate(90deg);
    }

    & .icon-next {
      transform: rotate(270deg);
    }
  }

  .footer-right {
    margin-left: auto;
    display: flex;
    justify-content: space-between;
    gap: 1em;

    .time {
      padding-left: 1em;
      border-left: 1px solid var(--border-secondary);
      color: var(--text-02);
    }
  }

}
</style>
